/**
 * MoteAppButtonOnClickListener.java
 *
 * Created by Andrew Moss on 31 Oct 2010
 *
 * Contains a class for handling click events for most buttons in MoteApp
 */
package com.mossdev.android.moteapp;

import com.mossdev.android.moteapp.comms.ServerConnectionException;

import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

/**
 * @author Andrew Moss
 * 
 * This class implements OnClickListener is order to be used as a listener
 * object for most of the buttons in the MoteApp.
 * 
 * @implements OnClickListener
 *
 */
public class ButtonOnClickListener implements OnClickListener {

	private String cmd;
	
	/**
	 * The constructor for the ButtonOnClickListener class.
	 * 
	 * @param buttoncmd the string to be sent when the button is pressed
	 */
	public ButtonOnClickListener(String buttoncmd) {
		this.cmd = buttoncmd;
	}
	
	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
	      //Get cmd from user
	      try {
	    	  MoteApp.servercomms.sendCommand(this.cmd);
	      } catch (ServerConnectionException e) {
	    	  Log.e(Config.LogTag, e.err_msg);
	      }
	}

}
